package com.spring.springAop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//切面
@Aspect
public class Audience {
    /*@Before("execution(**com.spring.springAop.Performance.perform(..))")//表演之前
    public void silenceCellPhones(){
        System.out.println("Sliencing cell phone");
    }
    @Before("execution(**com.spring.springAop.Performance.perform(..))") //表演之前
    public void takeSeats(){
        System.out.println("Taking seats");
    }
    @AfterReturning("execution(**com.spring.springAop.Performance.perform(..))") //表演之后
    public void applause(){
        System.out.println("CLAP CLAP CLAP!");
    }
    @AfterThrowing("execution(**com.spring.springAop.Performance.perform(..))")  //表演失败之后
    public void demandRefund(){
        System.out.println("Demanding a refund");
    }
    */

    @Pointcut("execution(** com.spring.springAop.Performance.perform(..))")
    public void performance(){}

    /*@Before("performance()")
    public void silenceCellPhones(){
        System.out.println("Sliencing cell phone");
    }
    @Before("performance()")
    public void takeSeats(){
        System.out.println("Taking seats");
    }
    @AfterReturning("performance()")
    public void applause(){
        System.out.println("CLAP CLAP CLAP!");
    }
    @AfterThrowing("performance()")
    public void demandRefund(){
        System.out.println("Demanding a refund");
    }*/
    @Around("performance()")
    public void watchPerformance(ProceedingJoinPoint jp){
        try{
            System.out.println("Silencing cell phone");
            System.out.println("Taking seats");
            jp.proceed();
            System.out.println("CLAP CLAP CLAP!");

        }catch (Throwable e){
            System.out.println("Demanding a refund");

        }
    }

}
